{"componentChunkName":"component---src-templates-blog-template-js","path":"/blog/a-bash-script-to-create-new-markdown-files-from-a-template","result":{"data":{"markdownRemark":{"html":"<p>This blog used to a be a single HTML page which was getting a bit large.\nI have converted it to a Gatsby (React) site based around markdown pages.</p>\n<p>One task I wanted to automate was creating well-named markdown files for each blog post.</p>\n<p>I wanted to be able to type in bash:</p>\n<pre><code>mknewmd \"Book review Pro ASP.NET Core MVC 2 by Adam Freeman\"\n</code></pre>\n<p>and to have a file named <code>book-review-pro-aspnet-core-mvc-2-by-adam-freeman.md</code> created for me, with the contents of a template <code>empty.md</code> for me to paste the content into. So, all lower case, spaces turned into hyphens and no special characters or dots.</p>\n<p>I used two inline bash functions for this. First <code>lowerdashed</code>:</p>\n<ul>\n<li>turns the spaces into hyphens</li>\n<li>\n<p>makes all alphabetic chars lower case\nlike this:</p>\n<pre><code>lowerdashed() {  hyphensInsteadOfSpaces=${1// /-}  ; lowerAndHyphenated=$(sed  's/[^a-zA-Z0-9-]//g' &#x3C;&#x3C;&#x3C; \"$hyphensInsteadOfSpaces\" ) ; echo \"$lowerAndHyphenated\" ; }\n</code></pre>\n<p>Then <code>mknewmd</code>:</p>\n</li>\n<li>\n<p>copies the template <code>empty.md</code> file into a new file with the appropriately cleaned file name (returned by <code>lowerdashed</code>)\nlike this:</p>\n<pre><code>mknewmd() { cleaned=$(lowerdashed \"$1\") ;  cp src/markdown-pages/empty.md \"src/markdown-pages/$cleaned.md\" ; }\n</code></pre>\n</li>\n</ul>","frontmatter":{"date":"October 03, 2020","slug":"/blog/a-bash-script-to-create-new-markdown-files-from-a-template","title":"A bash script to create new markdown files from a template"}}},"pageContext":{"slug":"/blog/a-bash-script-to-create-new-markdown-files-from-a-template"}},"staticQueryHashes":["3649515864"]}